<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 14-5-12
 * Time: 下午4:52
 * To change this template use File | Settings | File Templates.
 */
include_once dirname(__FILE__) . '/../common/dbConn.php';
function lawSear_func($arg_body){
    try{

        global $msgArray;
//        $log->info("===================register_func begin=====================");
//        $log->info("传入参数：");
//        $log->info($arg_body);
        if(!array_key_exists("search_key",$arg_body)){
            return MsgArray(false,"关键字参数错误",[],"Warn");
        }
        if(!array_key_exists("law_required",$arg_body)){
            return MsgArray(false,"法律参数错误",[],"Warn");
        }

        if(!array_key_exists("case_required",$arg_body)){
            return MsgArray(false,"案例参数错误",[],"Warn");
        }

        if(!array_key_exists("expect_required",$arg_body)){
            return MsgArray(false,"专家意见参数错误",[],"Warn");
        }

        $rsl = MsgArray(false,"操作失败!",[],"Warn");

        $q_pdo=connectDatabase();

        if(null==$q_pdo){
            return MsgArray(false,"数据库连接异常",[],"Warn");
        }
        $q_pdo->beginTransaction();
        $key = " CONTENT_TYPE,CONTENT,WHICH_LAW,WHICH_RULE";
        $where = "WHERE 1=1";
        $sql = "SELECT".$key." FROM T_LAW  ".$where."";

        if($arg_body["law_required"]==""&&$arg_body["case_required"]==""&&$arg_body["expect_required"]==""){
            return  MsgArray(false,"请先选择搜索类别！",[],"Warn");
        }
        if($arg_body["law_required"]!=""){
            if($where=="WHERE 1=1"){
            $where ="  WHERE (CONTENT_TYPE ='".$arg_body["law_required"]."'";
            }else{
                $where =$where." OR  CONTENT_TYPE ='".$arg_body["law_required"]."'";
            }
        }
        if($arg_body["case_required"]!=""){
            if($where=="WHERE 1=1"){
                $where ="  WHERE (CONTENT_TYPE ='".$arg_body["case_required"]."'";
            }else{
                $where =$where." OR  CONTENT_TYPE ='".$arg_body["case_required"]."'";
            }
        }

        if($arg_body["expect_required"]!=""){
            if($where=="WHERE 1=1"){
                $where ="  WHERE (CONTENT_TYPE ='".$arg_body["expect_required"]."'";
            }else{
                $where =$where." OR  CONTENT_TYPE ='".$arg_body["expect_required"]."'";
            }
        }

        $where = $where .")";

        if($arg_body["search_key"]!=""){
            if($where=="WHERE 1=1"){
                $where =" WHERE CONTENT LIKE '%".$arg_body["search_key"]."%'";
            }else{
                $where =$where." AND ( CONTENT LIKE '%".$arg_body["search_key"]."%' OR WHICH_RULE LIKE '%".$arg_body["search_key"]."%' OR WHICH_LAW LIKE '%".$arg_body["search_key"]."%')";
            }
        }

        $sql = "SELECT".$key." FROM T_LAW  ".$where."";
        $rs_cursor = $q_pdo->query($sql);
        $rs_cursor->setFetchMode(PDO::FETCH_ASSOC);
        $rs = $rs_cursor->fetchAll();

        return  MsgArray(true,"获取成功！",$rs,"success");


    }catch (Exception $e){

        return MsgArray(false,"系统异常",[],"Error");
    }
}